package com.deer.wms.base.system.web.plan;

import com.deer.wms.base.system.model.bar.BarCode;
import com.deer.wms.base.system.model.bar.BarCodeDto;
import com.deer.wms.base.system.model.box.BoxItemCriteria;
import com.deer.wms.base.system.model.box.BoxItemDto;
import com.deer.wms.base.system.model.plan.SchedulePlan;
import com.deer.wms.base.system.model.plan.SchedulePlanCriteria;
import com.deer.wms.base.system.service.plan.IPlanSetService;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.domain.AjaxResult;
import com.deer.wms.common.core.page.TableDataInfo;
import com.deer.wms.common.utils.poi.ExcelUtil;
import com.deer.wms.system.domain.SysPost;
import com.github.pagehelper.PageHelper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/planset")
public class PlanSetController extends BaseController {

    private String prefix = "planset";

    @Autowired
    private IPlanSetService planSetService;

    @RequiresPermissions("work:plan:view")
    @RequestMapping("plan")
    public String planSet() {
        return prefix + "/plan";
    }

    @PostMapping("/findList")
    @ResponseBody
    public TableDataInfo listPlan(SchedulePlanCriteria plan)
    {
        PageHelper.startPage(plan.getPageNum(),plan.getPageSize());
        List<SchedulePlan> list = planSetService.selectPlanList(plan);
        return getDataTable(list);
    }

    @PostMapping("/List")
    @ResponseBody
    public TableDataInfo findList(SchedulePlan schedulePlan) {
        startPage();
        List<SchedulePlan> list = planSetService.findList(schedulePlan);
        return getDataTable(list);
    }
    /*新增跳转 */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }
    /*新增保存*/
    @RequiresPermissions("work:plan:add")
    @PostMapping("/insert")
    @ResponseBody
    @Transactional
    public AjaxResult insert(SchedulePlan schedulePlan){
        return toAjax(planSetService.saveSchedulePlan(schedulePlan));
    }
    /**
     * 删除
     * @param ids
     * @return
     */
    @RequiresPermissions("work:plan:remove")
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids){
        return toAjax(planSetService.delectBarCodeByPids(ids));
    }

    /*修改跳转页面*/
    @GetMapping("/edit/{pid}")
    public String edit(@PathVariable("pid") Integer pid, ModelMap mmap)
    {
        SchedulePlan schedulePlan = planSetService.findByPid(pid);
        mmap.put("schedulePlan", schedulePlan);
        return prefix+"/edit";
    }
    /*修改保存数据*/
    @RequiresPermissions("work:plan:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SchedulePlan schedulePlan){
        return toAjax(planSetService.updateSchedulePlan(schedulePlan));
    }

   /***
    *班次信息导出
    * @param boxItemCriteria
    * @author 李帅辰
    * @date 2020/9/24 11:51
    * @return com.deer.wms.common.core.domain.AjaxResult
    */
    @RequiresPermissions(" work:plan:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SchedulePlan schedulePlan)
    {
        List<SchedulePlan> list = planSetService.findList(schedulePlan);
        ExcelUtil<SchedulePlan> util = new ExcelUtil<SchedulePlan>(SchedulePlan.class);
        return util.exportExcel(list, "班次");
    }
}
